//
//  FXNotificationEvent.swift
//  FXEvent
//
//  Created by Fanxx on 2021/11/23.
//

import Foundation

open class FXNotificationEvent: FXEvent<[AnyHashable: Any]?> {
    public let name: Notification.Name
    public init(name: Notification.Name) {
        self.name = name
        super.init()
        NotificationCenter.default.addObserver(self, selector: #selector(self.run(_:)), name: name, object: nil)
    }
    deinit {
        NotificationCenter.default.removeObserver(self)
    }
    @objc func run(_ notification: Notification) {
        super.sendActions(for: notification.userInfo)
    }
    open override func sendActions(for parameter: [AnyHashable: Any]?) {
        NotificationCenter.default.post(name: self.name, object: nil, userInfo: parameter)
    }
}
